var baseHandle = require("../../../pages/template/baseHandle.js");
import shareholderServ from "./shareholderServ";
Page(Object.assign({}, baseHandle,{
    data:{
        frontIdcard:'https://zysj-pro.oss-cn-shenzhen.aliyuncs.com/app/frontPage.png',
        reverseIdcard:'https://zysj-pro.oss-cn-shenzhen.aliyuncs.com/app/reversePage.png',
        accountStatement:'https://zysj-pro.oss-cn-shenzhen.aliyuncs.com/app/bill.png'
    },
    uploadImg(e){
        let that = this;
        let { name } = e.currentTarget.dataset;
        let dataList = this.data;
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                let tempFilePaths = res.tempFilePaths[0];
                that.uploadFile('image', false, tempFilePaths, (newFilePath) => {
                    dataList[name] = newFilePath
                    that.setData({
                        ...dataList
                    })
                });
            }})
    }, 
    submit(){
        let accountId =wx.getStorageSync('userId');
        let cusmallToken = wx.getStorageSync('cusmallToken');
        let {frontIdcard,reverseIdcard,accountStatement} =  this.data;
        let param = {frontIdcard,accountId,reverseIdcard,accountStatement,cusmallToken};
        
        if(frontIdcard.indexOf("app") != -1||reverseIdcard.indexOf("app") != -1||accountStatement.indexOf("app") != -1){
            wx.showToast({
                title: '资料不能为空',
                icon: 'none',
                duration: 2000
              })
            return ;
        }
        wx.showLoading({
            title: '加载中',
          })
        shareholderServ.addCouponsApply(param).then((res)=>{
           if(res.ret==0){
            wx.showToast({
                title: '提交成功，正在审核',
                icon: 'success',
                duration: 2000
            })
            wx.redirectTo({
                url:'/subPackages2/pages/shareholder/submitList'
            })              
           }
           wx.hideLoading()
        })
    }
}));